<template>
  <div>
    <!-- 找房 -->
    <div class="header">
      <div class="search">
        <van-icon name="arrow-left" color="#fff" class="left-io" size="20" />
        <div class="search-box">
          <div class="left">
            <span @click="$router.push('/city')">{{ cityName }}</span>
            <van-icon
              class="iconfont"
              class-prefix="icon"
              name="xialakuangxiala"
              size="25"
              color="#000000"
            />
            <van-icon name="search" color="#c4c6c7" size="20" class="search" />
          </div>
          <input type="text" placeholder="请输入小区或地区" />
        </div>
        <van-icon name="photo-o" size="25" color="#ffffff" class="right-io" />
      </div>
    </div>
    <van-dropdown-menu active-color="#21b97a">
      <van-dropdown-item title="区域" ref="area">
        <van-picker :columns="columns" />
        <van-button type="primary" class="cancel" @click="onConfirm">
          取消
        </van-button>
        <van-button type="primary" class="confirm" @click="onConfirm">
          确认
        </van-button>
      </van-dropdown-item>
      <van-dropdown-item title="方式" ref="area">
        <van-picker :columns="way" />
        <van-button type="primary" class="cancel" @click="onConfirm">
          取消
        </van-button>
        <van-button type="primary" class="confirm" @click="onConfirm">
          确认
        </van-button>
      </van-dropdown-item>
      <van-dropdown-item title="租金" ref="area">
        <van-picker :columns="price" />
        <van-button type="primary" class="cancel" @click="onConfirm">
          取消
        </van-button>
        <van-button type="primary" class="confirm" @click="onConfirm">
          确认
        </van-button>
      </van-dropdown-item>
      <van-dropdown-item title="筛选" ref="item">
      </van-dropdown-item>
    </van-dropdown-menu>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <HouseState :list="list" class="houseContent"></HouseState>
    </van-list>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getHouse } from '@/api/city'
export default {
  name: 'find-page',
  data () {
    return {
      city: '',
      value: 0,
      switch1: false,
      switch2: false,
      columns: [
        {
          text: '区域',
          children: [
            {
              text: '杭州',
              children: [{ text: '西湖区' }, { text: '余杭区' }]
            },
            {
              text: '温州',
              children: [{ text: '鹿城区' }, { text: '瓯海区' }]
            }
          ]
        },
        {
          text: '地铁',
          children: [
            {
              text: '2号线',
              children: [{ text: '良渚' }, { text: '朝阳' }]
            },
            {
              text: '1号线',
              children: [{ text: '文泽路' }, { text: '打铁关' }]
            }
          ]
        }
      ],
      way: ['不限', '整租', '合租'],
      price: [
        '不限',
        '1000及以下',
        '1000-2000',
        '2000-3000',
        '3000-4000',
        '4000-5000',
        '5000-7000',
        '7000以上'
      ],
      list: [],
      loading: false,
      finished: false,
      newObj: {
        cityId: '',
        start: 1,
        end: 20
      }
    }
  },
  async created () {},
  methods: {
    arrive (index) {
      this.$router.push({ name: 'contented', query: { index } })
    },
    onConfirm () {
      this.$refs.item.toggle()
    },
    async onLoad () {
      this.newObj.cityId = this.cityId
      const data = await getHouse(this.newObj)
      this.list = [...this.list, ...data.body.list]
      this.loading = false
      this.newObj.start += 20
      this.newObj.end += 20
      if (this.newObj.end > data.body.count) {
        this.finished = true
      }
      console.log(data)
      console.log(this.list)
    }
  },
  computed: {
    ...mapState('user', ['cityName', 'cityId'])
  }
}
</script>

<style scoped lang="less">
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.header {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 50px;
  background-color: #21b97a;
  .search {
    position: absolute;
    top: 5px;
    left: 20px;
    height: 40px;
    width: 90%;
    display: flex;
    justify-content: space-between;
    align-content: center;
    font-size: 14px;
    padding: 5px 0px 10px 0px;
    background-color: rgba(0, 0, 0, 0);
    .left-io {
      position: relative;
      left: -10px;
      top: 5px;
    }
    .right-io {
      position: relative;
      right: -10px;
      top: 3px;
    }
    .search-box {
      display: flex;
      width: 300px;
      height: 30px;
      padding: 5px 0;
      border-radius: 3px;
      background-color: #fff;
      .left {
        width: 60px;
        text-align: center;
        position: relative;
        display: flex;
        border-right: 1px solid #ccc;
        .search {
          position: absolute;
          left: 62px;
          top: -5px;
        }
        span {
          z-index: 1000;
          position: relative;
          left: 10px;
          top: 1px;
          margin-right: 5px;
        }
      }
      input {
        position: absolute;
        width: 210px;
        top: 5px;
        right: 25px;
        z-index: 1000;
        flex: 1;
        height: 26px;
        border: none;
        &::placeholder {
          position: absolute;
          top: 5px;
        }
      }
    }
  }
}
.cancel {
  width: 30%;
  background-color: #fff;
  color: #21b97a;
  border: 1px solid #ccc;
}
.confirm {
  width: 70%;
}
li {
  list-style: none;
}
</style>
